//
//  ReadandWriteJson.m
//  MyjsonParser
//
//  Created by xigua on 11-11-21.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ReadandWriteJson.h"
#import "JSONKit.h"

@implementation ReadandWriteJson

/*
 读取本地的json文件
 */
+(NSMutableDictionary *)readJsonToDic:(NSString *)filepath{
	NSString *getstr1=[NSString stringWithContentsOfFile:filepath];
	NSMutableDictionary *getdic=[getstr1 objectFromJSONString];//把一个字符串读取为字典
	NSMutableDictionary  *newDic=[[NSMutableDictionary alloc] init];
	NSArray	  *allkey=[getdic allKeys];
	for(NSString *key in allkey){
		[newDic setObject:[getdic objectForKey:key] forKey:key];
	}
	return [newDic autorelease];
}
/*
 把字典写入本地，传来的是文件路径
 */
+(void)writeDicToLocalfile:(NSMutableDictionary *)sourceDic  filepath:(NSString *)filepath{
	NSString *content=[sourceDic JSONString];//把一个字典读取为字符串
	////NSLog(@"content..........%@",content);
	[content writeToFile:filepath atomically:YES];
}

@end
